package com.wmx.thread.atomic;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;

/**********************************
 * @author wmx
 * @date 2019/8/22 11:09
 * @description:
 * @version 1.0
 ************************************/
public class AtomicReferenceTest {
    public static void main(String[] args) {
        Simple simple1 = new Simple(100);
        AtomicReference<Simple> atomicReference = new AtomicReference<>(simple1);
        simple1.setId(101);
        boolean b = atomicReference.compareAndSet(new Simple(100), new Simple(102));
        System.out.println("是否修改成功=================" + b);
        System.out.println(atomicReference.get());
        /*
        TimeUnit.DAYS          //天
        TimeUnit.HOURS         //小时
        TimeUnit.MINUTES       //分钟
        TimeUnit.SECONDS       //秒
        TimeUnit.MILLISECONDS  //毫秒*/

        try {
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        } finally {
        }
    }

}

@Getter
@Setter
@AllArgsConstructor
@ToString
class Simple {
    private int id;
}